Import mojo
Import agfx

Class TUniMouse

	
	
	Private
	
	Field bHit:Int=0
	Field bDown:Int=0
	Field bUp:Int=False
	Field btn_state:Int[]=[0,0,0,0,0,0,0,0,0]
	
	
	Public
	
	Field x:Int
	Field y:Int
	
	'|---------------------------------------------------------------------------------------
	'| CONSTRUCTOR
	'|---------------------------------------------------------------------------------------
	Method New()
		
	End
	
	'|---------------------------------------------------------------------------------------
	'| UPDATE
	'|---------------------------------------------------------------------------------------
	Method Update()
	
		If DISPLAY.IsVirtualScaleUsed()
			Self.x = DISPLAY.VMouseX()
			Self.y = DISPLAY.VMouseY()
		Else
			Self.x = MouseX()
			Self.y = MouseY()

		Endif
	End
	
	'|---------------------------------------------------------------------------------------
	'| Check Mouse HIT
	'|---------------------------------------------------------------------------------------
	Method Hit:Int(button:Int=MOUSE_LEFT)	
	
		#If TARGET="android" Or TARGET="ios" Then
			Self.bHit = TouchHit(button)
		#Else 
			Self.bHit = MouseHit(button)
		#End
		
		Return Self.bHit
	End

	'|---------------------------------------------------------------------------------------
	'| Check Mouse DOWN
	'|---------------------------------------------------------------------------------------
	Method Down:Int(button:Int=MOUSE_LEFT)
		
		'Self.bDown = MouseDown(button)	
		
		#If TARGET="android" Or TARGET="ios" Then
			Self.bDown = TouchDown(button)
		#Else 
			Self.bDown = MouseDown(button)
		#End
			
		Return Self.bDown
	End
	
	'|---------------------------------------------------------------------------------------
	'| Check Mouse UP
	'|---------------------------------------------------------------------------------------
	Method Up:Int(button:Int=MOUSE_LEFT)	
		
		Local down = -1
		
		#If TARGET="android" Or TARGET="ios" Then
			down = TouchDown(button)
		#Else 
			down = MouseDown(button)
		#End
		
		If down
			Self.btn_state[button]=True
			Return False
		End
		
		If Self.btn_state[button]=True And down = False Then
			Self.btn_state[button]=False
			Return True
		End
		
		Return False
	End
	
	'|---------------------------------------------------------------------------------------
	'| Check Mouse in Rectangle
	'|---------------------------------------------------------------------------------------
	Method IsInRect:Bool(x:Int,y:Int,w:Int,h:Int)
		Local res:Bool = False
		If MOUSE.x>x And MOUSE.x<(x+w) And MOUSE.y>y And MOUSE.y<(y+h) Then res = True
		Return res
	End Method
	
	'|---------------------------------------------------------------------------------------
	'| Check Mouse in Rectangle
	'|---------------------------------------------------------------------------------------
	Method IsInRect:Bool(pos:TVector2,size:TVector2)
		Return Self.IsInRect(pos.x,pos.y,size.x,size.y)
	End Method
	
End


